#!/bin/bash

# postinst script for system-network
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown dladm:netadm $BASEDIR/etc/dladm
	chown netadm:netadm $BASEDIR/etc/nwam
	chown netadm:netadm $BASEDIR/etc/nwam/loc
	chown netadm:netadm $BASEDIR/etc/nwam/loc/NoNet
	chown root:sys $BASEDIR/etc/inet/secret
	chown root:sys $BASEDIR/etc/inet/secret/ike.privatekeys
	chown root:sys $BASEDIR/etc/inet
	chown root:sys $BASEDIR/etc/inet/ike
	chown root:sys $BASEDIR/etc/inet/ike/crls
	chown root:sys $BASEDIR/etc/inet/ike/publickeys
	chown root:sys $BASEDIR/lib/svc/manifest/network/ipsec
	chown root:sys $BASEDIR/var/svc/manifest/network/ipsec
	chmod 0555 "$BASEDIR/lib/inet/in.mpathd"
	chown root:bin "$BASEDIR/lib/inet/in.mpathd"
	chmod 0555 "$BASEDIR/lib/inet/ipmgmtd"
	chown root:bin "$BASEDIR/lib/inet/ipmgmtd"
	chmod 0555 "$BASEDIR/lib/inet/netcfgd"
	chown root:bin "$BASEDIR/lib/inet/netcfgd"
	chmod 0555 "$BASEDIR/lib/inet/nwamd"
	chown root:bin "$BASEDIR/lib/inet/nwamd"
	chmod 0555 "$BASEDIR/lib/svc/method/net-init"
	chown root:bin "$BASEDIR/lib/svc/method/net-init"
	chmod 0555 "$BASEDIR/lib/svc/method/net-install"
	chown root:bin "$BASEDIR/lib/svc/method/net-install"
	chmod 0555 "$BASEDIR/lib/svc/method/net-ipmgmt"
	chown root:bin "$BASEDIR/lib/svc/method/net-ipmgmt"
	chmod 0555 "$BASEDIR/lib/svc/method/net-ipmp"
	chown root:bin "$BASEDIR/lib/svc/method/net-ipmp"
	chmod 0555 "$BASEDIR/lib/svc/method/net-iptun"
	chown root:bin "$BASEDIR/lib/svc/method/net-iptun"
	chmod 0555 "$BASEDIR/lib/svc/method/svc-dlmgmtd"
	chown root:bin "$BASEDIR/lib/svc/method/svc-dlmgmtd"
	chmod 0555 "$BASEDIR/sbin/dladm"
	chown root:bin "$BASEDIR/sbin/dladm"
	chmod 0555 "$BASEDIR/sbin/dlmgmtd"
	chown root:bin "$BASEDIR/sbin/dlmgmtd"
	chmod 0555 "$BASEDIR/sbin/dlstat"
	chown root:bin "$BASEDIR/sbin/dlstat"
	chmod 0555 "$BASEDIR/sbin/flowadm"
	chown root:bin "$BASEDIR/sbin/flowadm"
	chmod 0555 "$BASEDIR/sbin/flowstat"
	chown root:bin "$BASEDIR/sbin/flowstat"
	chmod 0555 "$BASEDIR/usr/bin/vndstat"
	chown root:bin "$BASEDIR/usr/bin/vndstat"
	chmod 0555 "$BASEDIR/usr/sbin/6to4relay"
	chown root:bin "$BASEDIR/usr/sbin/6to4relay"
	chmod 0555 "$BASEDIR/usr/sbin/ikeadm"
	chown root:bin "$BASEDIR/usr/sbin/ikeadm"
	chmod 0555 "$BASEDIR/usr/sbin/ikecert"
	chown root:bin "$BASEDIR/usr/sbin/ikecert"
	chmod 0555 "$BASEDIR/usr/sbin/ipaddrsel"
	chown root:bin "$BASEDIR/usr/sbin/ipaddrsel"
	chmod 0555 "$BASEDIR/usr/sbin/ipsecconf"
	chown root:bin "$BASEDIR/usr/sbin/ipsecconf"
	chmod 0555 "$BASEDIR/usr/sbin/ipseckey"
	chown root:bin "$BASEDIR/usr/sbin/ipseckey"
	chmod 0555 "$BASEDIR/usr/sbin/ndd"
	chown root:bin "$BASEDIR/usr/sbin/ndd"
	chmod 0555 "$BASEDIR/usr/sbin/nwamadm"
	chown root:bin "$BASEDIR/usr/sbin/nwamadm"
	chmod 0555 "$BASEDIR/usr/sbin/nwamcfg"
	chown root:bin "$BASEDIR/usr/sbin/nwamcfg"
	chmod 0555 "$BASEDIR/usr/sbin/vndadm"
	chown root:bin "$BASEDIR/usr/sbin/vndadm"
	[ -f $BASEDIR/etc/dladm/datalink.conf ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/datalink.conf $BASEDIR/etc/dladm/datalink.conf
	chmod 0644 "$BASEDIR/etc/dladm/datalink.conf"
	chown dladm:netadm "$BASEDIR/etc/dladm/datalink.conf"
	[ -f $BASEDIR/etc/dladm/flowadm.conf ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/flowadm.conf $BASEDIR/etc/dladm/flowadm.conf
	chmod 0644 "$BASEDIR/etc/dladm/flowadm.conf"
	chown dladm:netadm "$BASEDIR/etc/dladm/flowadm.conf"
	[ -f $BASEDIR/etc/dladm/flowprop.conf ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/flowprop.conf $BASEDIR/etc/dladm/flowprop.conf
	chmod 0644 "$BASEDIR/etc/dladm/flowprop.conf"
	chown dladm:netadm "$BASEDIR/etc/dladm/flowprop.conf"
	[ -f $BASEDIR/etc/nwam/loc/NoNet/ipf.conf.dfl ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/ipf.conf.dfl $BASEDIR/etc/nwam/loc/NoNet/ipf.conf.dfl
	chmod 0644 "$BASEDIR/etc/nwam/loc/NoNet/ipf.conf.dfl"
	chown netadm:netadm "$BASEDIR/etc/nwam/loc/NoNet/ipf.conf.dfl"
	[ -f $BASEDIR/etc/nwam/loc/NoNet/ipf6.conf.dfl ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/ipf6.conf.dfl $BASEDIR/etc/nwam/loc/NoNet/ipf6.conf.dfl
	chmod 0644 "$BASEDIR/etc/nwam/loc/NoNet/ipf6.conf.dfl"
	chown netadm:netadm "$BASEDIR/etc/nwam/loc/NoNet/ipf6.conf.dfl"
	[ -f $BASEDIR/etc/nwam/loc/create_loc_auto ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/create_loc_auto $BASEDIR/etc/nwam/loc/create_loc_auto
	chmod 0644 "$BASEDIR/etc/nwam/loc/create_loc_auto"
	chown netadm:netadm "$BASEDIR/etc/nwam/loc/create_loc_auto"
	[ -f $BASEDIR/etc/nwam/loc/create_loc_nonet ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/create_loc_nonet $BASEDIR/etc/nwam/loc/create_loc_nonet
	chmod 0644 "$BASEDIR/etc/nwam/loc/create_loc_nonet"
	chown netadm:netadm "$BASEDIR/etc/nwam/loc/create_loc_nonet"
	[ -f $BASEDIR/etc/dladm/secobj.conf ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/secobj.conf $BASEDIR/etc/dladm/secobj.conf
	chmod 0660 "$BASEDIR/etc/dladm/secobj.conf"
	chown dladm:netadm "$BASEDIR/etc/dladm/secobj.conf"
	chmod 0444 "$BASEDIR/etc/inet/datemsk.ndpd"
	chown root:sys "$BASEDIR/etc/inet/datemsk.ndpd"
	chmod 0444 "$BASEDIR/etc/inet/ike/config.sample"
	chown root:sys "$BASEDIR/etc/inet/ike/config.sample"
	chmod 0444 "$BASEDIR/etc/inet/ipsecinit.sample"
	chown root:sys "$BASEDIR/etc/inet/ipsecinit.sample"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/dlmgmt.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/dlmgmt.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/ipsec/ike.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/ipsec/ike.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/ipsec/ipsecalgs.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/ipsec/ipsecalgs.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/ipsec/manual-key.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/ipsec/manual-key.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/ipsec/policy.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/ipsec/policy.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/network-initial.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/network-initial.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/network-install.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/network-install.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/network-ipmgmt.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/network-ipmgmt.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/network-ipmp.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/network-ipmp.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/network-iptun.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/network-iptun.xml"
	[ -f $BASEDIR/etc/inet/secret/ike.preshared ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/ike.preshared $BASEDIR/etc/inet/secret/ike.preshared
	chmod 0600 "$BASEDIR/etc/inet/secret/ike.preshared"
	chown root:sys "$BASEDIR/etc/inet/secret/ike.preshared"
	chmod 0600 "$BASEDIR/etc/inet/secret/ipseckeys.sample"
	chown root:sys "$BASEDIR/etc/inet/secret/ipseckeys.sample"
	[ -f $BASEDIR/etc/default/dhcpagent ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/dhcpagent $BASEDIR/etc/default/dhcpagent
	chmod 0644 "$BASEDIR/etc/default/dhcpagent"
	chown root:sys "$BASEDIR/etc/default/dhcpagent"
	[ -f $BASEDIR/etc/default/inetinit ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/inetinit $BASEDIR/etc/default/inetinit
	chmod 0644 "$BASEDIR/etc/default/inetinit"
	chown root:sys "$BASEDIR/etc/default/inetinit"
	[ -f $BASEDIR/etc/default/ipsec ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/ipsec $BASEDIR/etc/default/ipsec
	chmod 0644 "$BASEDIR/etc/default/ipsec"
	chown root:sys "$BASEDIR/etc/default/ipsec"
	[ -f $BASEDIR/etc/default/mpathd ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/mpathd $BASEDIR/etc/default/mpathd
	chmod 0644 "$BASEDIR/etc/default/mpathd"
	chown root:sys "$BASEDIR/etc/default/mpathd"
	[ -f $BASEDIR/etc/inet/ipsecalgs ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/ipsecalgs $BASEDIR/etc/inet/ipsecalgs
	chmod 0644 "$BASEDIR/etc/inet/ipsecalgs"
	chown root:sys "$BASEDIR/etc/inet/ipsecalgs"
	[ -f $BASEDIR/etc/inet/ipaddrsel.conf ] || cp -ax $BASEDIR/usr/share/doc/system-network/examples/ipaddrsel.conf $BASEDIR/etc/inet/ipaddrsel.conf
	chmod 0644 "$BASEDIR/etc/inet/ipaddrsel.conf"
	chown root:sys "$BASEDIR/etc/inet/ipaddrsel.conf"
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

